package com.auxgroup.smarthome.inner.controller;

import com.auxgroup.bridge.app.inner.vo.DeviceFaultVo;
import com.auxgroup.smarthome.inner.service.DeviceFaultService;
import com.auxgroup.smarthome.utils.PageContent;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备故障相关API
 * Created by lixiaoxiao on 17-8-7.
 */
@Api(description = "设备故障", tags = "设备故障")
@RestController
public class DeviceFaultController {

    @Autowired
    private DeviceFaultService deviceFaultService;

    @ApiOperation(value = "设备故障列表", notes = "设备故障--获取故障列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "mac/用户名/手机号", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "integer", required = false),
            @ApiImplicitParam(name = "size", value = "分页大小", paramType = "query", dataType = "integer", required = false),
            @ApiImplicitParam(name = "status", value = "状态(1: 未解决0: 已解决)", paramType = "query", dataType = "integer", required = true)
    })
    @RequestMapping(value = "/device_fault", method = RequestMethod.GET)
    public ApiResponse<PageContent<DeviceFaultVo>> getDeviceFaultList(@RequestParam(required = false) String keyword,
                                                                      @RequestParam(defaultValue = "0", required = false) Integer page,
                                                                      @RequestParam(defaultValue = "5", required = false) Integer size,
                                                                      @RequestParam(required = true) Integer status) {
        return ApiResponse.ok(deviceFaultService.findDeviceFaultList(keyword, page, size,status));
    }

    @ApiOperation(value = "app设备故障列表", notes = "设备故障--app获取故障列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mac", value = "mac", paramType = "query", dataType = "string", required = true)
    })
    @RequestMapping(value = "/devices/faults", method = RequestMethod.GET)
    public ApiResponse<List<DeviceFaultVo>> getAppDeviceFaultList(@RequestParam(required = true) String mac) {
        return ApiResponse.ok(deviceFaultService.findAppDeviceFaultList(mac));
    }

    @ApiOperation(value = "app设备历史故障", notes = "设备故障--app获取历史故障")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "uid", paramType = "query", dataType = "string", required = true)
    })
    @RequestMapping(value = "/devices/faultsHis", method = RequestMethod.GET)
    public ApiResponse<List<DeviceFaultVo>> getAppDeviceHisFaultList(@RequestParam(required = true) String uid) {
        return ApiResponse.ok(deviceFaultService.findAppDeviceHisFaultList(uid));
    }

}